<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
    <base href="/oa1/" />
    <title>添加名片夹</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="static/bootstrapvalidator/css/bootstrapValidator.css" rel="stylesheet">
    <script src="static/jquery/jquery-1.10.2.min.js"></script>
    <script src="static/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="static/bootstrapvalidator/js/bootstrapValidator.js"></script>
</head>
<body>
<div class="container" style="margin-top: 30px;">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h4 class="panel-title">添加名片夹类型</h4>
        </div>
        <div class="panel-body">
            <!-- 表单提交到Controller的addMpCardtype方法 -->
            <form action="mp/cardtype/addMpCardtype" id="myform" method="post" class="form-horizontal" role="form">
                <div class="col-md-12">
                    <div class="form-group col-md-6">
                        <label for="type" class="col-md-4 control-label">类型名称<span style="color: red;">*</span></label>
                        <div class="col-md-8">
                            <!-- 新增时无需oid，仅提交type -->
                            <input type="text" id="type" name="type"
                                   class="form-control" placeholder="请输入1-10位类型名称"
                                   value="">
                        </div>
                    </div>
                </div>
                <div class="col-md-12">
                    <div class="form-group col-md-12">
                        <div class="col-md-10 col-md-offset-2">
                            <a href="mp/cardtype/listMpCardtype" class="btn btn-info">返回列表</a>
                            <button type="submit" class="btn btn-success">保存</button>
                            <button type="reset" class="btn btn-default">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        // 表单验证规则（与Controller的checkMpCardtypeName配合）
        $("#myform").bootstrapValidator({
            message: '输入值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                type: {
                    validators: {
                        notEmpty: { message: '类型名称不能为空' },
                        stringLength: {
                            min: 1, max: 10,
                            message: '名称长度必须在1-10位之间'
                        },
                        remote: {
                            url: "mp/cardtype/checkMpCardtypeName", // 调用Controller的校验方法
                            delay: 500, // 输入后延迟500ms校验
                            type: 'post',
                            message: '该类型名称已存在',
                            data: function(validator) {
                                return {
                                    name: $("#type").val(),
                                    oid: null // 新增时oid为null，无需排除自身
                                };
                            }
                        }
                    }
                }
            }
        });
    });
</script>
</body>
</html>